﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Baza.EF.BLL;
using Baza.EF.DAL;

using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web.UI.HtmlControls;

namespace Pep_3014_3070.Owners
{
    public partial class ApartmanDetails : System.Web.UI.Page
    {
        protected int ApartmanID
        {
            get { return (int)ViewState["apartmanID"]; }
            set { ViewState["apartmanID"] = value; }
        }
        //pomocna varijabla , s kojom imenujemo slike po broju slika(redosljedom). . .
        private int slikaID
        {
            get { return (int)ViewState["SlikaID"]; }
            set { ViewState["SlikaID"] = value; }
        }
        //u ovoj listi cemo cuvati listu opisa : razlog liste je sto moze korisnik dodati vise opisa na razlicitim jezicima
        private List<Descriptions> descriptionsList
        {
            get
            {
                if (this.ViewState["desc"] == null)
                {
                    this.ViewState["desc"] = new List<Descriptions>();
                }
                return (List<Descriptions>)(this.ViewState["desc"]);
            }
            set { this.ViewState["desc"] = value; }
        }
        //u ovoj listi su oni opisi koji su u bazi dodani
        private List<Descriptions> ListDescription
        {
            get
            {
                if (this.ViewState["descList"] == null)
                {
                    this.ViewState["descList"] = new List<Descriptions>();
                }
                return (List<Descriptions>)(this.ViewState["descList"]);
            }
            set { this.ViewState["descList"] = value; }
        }
        //lista slika : cuvamo URL-ove slika . . 
        private List<Pictures> picturesList
        {
            get
            {
                if (this.ViewState["pictures"] == null)
                {
                    this.ViewState["pictures"] = new List<Pictures>();
                }
                return (List<Pictures>)(this.ViewState["pictures"]);
            }
            set { this.ViewState["pictures"] = value; }
        }
        //lista cijena : cuvamo cijene za razlicite periode . . . 
        private List<Prices> pricesList
        {
            get
            {
                if (this.ViewState["prices"] == null)
                {
                    this.ViewState["prices"] = new List<Prices>();
                }
                return (List<Prices>)(this.ViewState["prices"]);
            }
            set { this.ViewState["prices"] = value; }
        }
        //Lista cijna ucitane iz baze, dodana radi mogucnosti brisanja iz baze . . 
        private List<ad_Owner_Apartmens_Prices_SELECT_BY_ApartmanID_Result> ListPrices
        {
            get
            {
                if (this.ViewState["pricesList"] == null)
                {
                    this.ViewState["pricesList"] = new List<ad_Owner_Apartmens_Prices_SELECT_BY_ApartmanID_Result>();
                }
                return (List<ad_Owner_Apartmens_Prices_SELECT_BY_ApartmanID_Result>)(this.ViewState["pricesList"]);
            }
            set { this.ViewState["pricesList"] = value; }
        }
        private List<int> LanguageID
        {
            get
            {
                if (this.ViewState["langID"] == null)
                    this.ViewState["langID"] = new List<int>();
                return (List<int>)this.ViewState["langID"];
            }
            set
            {
                this.ViewState["langID"] = value;
            }
        }
        //pomocna varijabla u kojoj cemo cuvati ID-ove opisa. . ovo nam je potrebno radi opcije brisanja Opisa...(u slucaju greske ili zelje korisnika) . . 
        private int DescriptionID
        {
            get { return (int)ViewState["descID"]; }
            set { this.ViewState["descID"] = value; }

        }
        //pomocna varijabla u kojoj cemo cuvati ID-ove . . takodjer potrebno radi mogucnosti brisanja cijena
        private int PriceID
        {
            get { return (int)ViewState["priceID"]; }
            set { this.ViewState["priceID"] = value; }

        }
        //Link od profilne slike . . .
        private string ProfilePictures
        {
            get { return (string)ViewState["profilePictures"]; }
            set { ViewState["profilePictures"] = value; }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ApartmanID = Convert.ToInt32(RouteData.Values["id"]);
                BindData();
                BindApartman();
                DescriptionID = 0;
                PriceID = 0;
            }
        }

        private void BindData()
        {
            //bind near by activities
            List<NearbyActivities> tempNA = DAOwners.getNearbyActivities();
            NearByActivitiesCheckBoxList.DataSource = tempNA;
            NearByActivitiesCheckBoxList.DataTextField = "Name";
            NearByActivitiesCheckBoxList.DataValueField = "NearbyActivitiID";
            NearByActivitiesCheckBoxList.DataBind();

            //bind amenities
            List<Amenities> tempA = DAOwners.getAmenities();
            AmenitiesCheckBoxList.DataSource = tempA;
            AmenitiesCheckBoxList.DataTextField = "Name";
            AmenitiesCheckBoxList.DataValueField = "AmenitiesID";
            AmenitiesCheckBoxList.DataBind();

            //Binde Country
            List<Countries> tempC = DARegistration.getAllCountres();
            Countries c = new Countries();
            c.Country_name = "*Odaberi Zemlju*";
            c.CountryID = 0;

            tempC.Insert(0, c);

            CountryDropDownList.DataSource = tempC;
            CountryDropDownList.DataTextField = "Country_name";
            CountryDropDownList.DataValueField = "CountryID";
            CountryDropDownList.DataBind();

            DescriptionLanguageDropDownList.DataSource = tempC;
            DescriptionLanguageDropDownList.DataTextField = "Country_name";
            DescriptionLanguageDropDownList.DataValueField = "CountryID";
            DescriptionLanguageDropDownList.DataBind();

            //Binde Currency

            List<Currency> tempCU = DAOwners.getCurrency();
            Currency curr = new Currency();
            curr.currency_code = "*Odaberi Valutu*";
            curr.currency_id = 0;
            tempCU.Insert(0, curr);
            CurrencyDropDownList.DataSource = tempCU;
            CurrencyDropDownList.DataTextField = "currency_code";
            CurrencyDropDownList.DataValueField = "currency_id";
            CurrencyDropDownList.DataBind();

            //Binde Apartment type 
            List<ApartmentType> tempAT = DAOwners.getApartmentType();

            ApartmentType a = new ApartmentType();
            a.Name = "*Odaberi Tip Apartmana*";
            a.ApartmentTypeID = 0;
            tempAT.Insert(0, a);

            TypeDropDownList.DataSource = tempAT;
            TypeDropDownList.DataTextField = "Name";
            TypeDropDownList.DataValueField = "ApartmentTypeID";
            TypeDropDownList.DataBind();
        }
        private void BindeNearbyActivities()
        {
            List<NearbyActivities> tempList = DAOwners.getNearbyActivitiesByApartmanID(ApartmanID);
            for (int i = 0; i < tempList.Count; i++)
            {

                for (int j = i; j < NearByActivitiesCheckBoxList.Items.Count; j++)
                {
                    if (tempList[i].NearbyActivitiID == Convert.ToInt32(NearByActivitiesCheckBoxList.Items[j].Value))
                        NearByActivitiesCheckBoxList.Items[j].Selected = true;

                }
            }



        }
        private void BindeAmenities()
        {
            List<Amenities> tempList = DAOwners.getAmenitiesByApartmanID(ApartmanID);

            for (int i = 0; i < tempList.Count; i++)
            {
                for (int j = i; j < AmenitiesCheckBoxList.Items.Count; j++)
                {
                    if (tempList[i].AmenitiesID == Convert.ToInt32(AmenitiesCheckBoxList.Items[j].Value))
                        AmenitiesCheckBoxList.Items[j].Selected = true;
                }
            }

        }
        private void BindApartman()
        {
            Apartments apartman = DAOwners.getApartmanByID(ApartmanID);

            ad_Owner_getNameByID_Result temp = DAOwners.getOwnerNameByID(Convert.ToInt32(HttpContext.Current.User.Identity.Name));
            lblNameIznajmljivac.Text = temp.FirstName + " " + temp.LastName;
            TitleInput.Text = apartman.Title;
            TypeDropDownList.SelectedIndex = apartman.ApartmentTypeID;
            BedroomsDropDownList.SelectedIndex = Convert.ToInt32(apartman.Bedrooms);

            DateTime dt = Convert.ToDateTime(apartman.CheckIn);
            CheckInInput.Text = dt.ToString("HH:mm");
            DateTime dt2 = Convert.ToDateTime(apartman.CheckOut);
            CheckOutInput.Text = dt2.ToString("HH:mm");
            DateTime dt3 = Convert.ToDateTime(apartman.AvgCleaningTime);
            AvgCleaningTimeInput.Text = dt3.ToString("HH:mm");

            BedsDropDownList.SelectedIndex = Convert.ToInt32(apartman.Beds);

            if (apartman.Elevator == true)
                ElevatorDropDownList.SelectedIndex = 1;
            else if (apartman.Elevator == false)
                ElevatorDropDownList.SelectedIndex = 2;

            FloorInputDropDownList.SelectedIndex = Convert.ToInt32(apartman.Floor);
            BathroomsDropDownList.SelectedIndex = Convert.ToInt32(apartman.Bathrooms);
            ToiletsDropDownList.SelectedIndex = Convert.ToInt32(apartman.Toilets);

            //Podaci sa cijenama . . . 
            BindePeriod();

            //Maximalni kapacitet
            MaxGuestDropDownList.SelectedIndex = Convert.ToInt32(apartman.MaxGuests);
            MaxAdultsDropDownList1.SelectedIndex = Convert.ToInt32(apartman.MaxAdults);
            MaxChlidrenDropDownList.SelectedIndex = Convert.ToInt32(apartman.MaxChildren);
            MaxBabiesDropDownList.SelectedIndex = Convert.ToInt32(apartman.MaxBabies);

            //Minimalna i maximalna ostajanja
            MinStayDropDownList.SelectedIndex = Convert.ToInt32(apartman.MinStay);
            MaxStayDropDownList.SelectedIndex = Convert.ToInt32(apartman.MaxStay);

            //Addressa
            BindeAddress(Convert.ToInt32(apartman.AdresID));

            //Pictures
            BindPictures();

            ProfileImage.ImageUrl = apartman.ProfilePictures;

            if (apartman.ProfilePictures != "")
            {
                //profilePicturesDIV.Visible = false;
                profilePictDIV.Visible = true;
            }

            RentalDetailsInput.Text = apartman.RentalDetails;
            InventoryInput.Text = apartman.Inventory;
            ArrivalSheetInput.Text = apartman.ArrivalSheet;

            //Ucitavanje Descriptions

            BindDescriptions();
        }
        private void BindPictures()
        {
            List<Pictures> picList = DAOwners.getPicturesByApartmanID(Convert.ToInt32(ApartmanID));

            Images2Repeater.DataSource = picList;
            Images2Repeater.DataBind();

        }
        private void BindDescriptions()
        {
             ListDescription = DAOwners.getDescriptionByApartmanID(ApartmanID);

            PostojeciOpisiRepeater.DataSource = ListDescription;
            PostojeciOpisiRepeater.DataBind();
            if (ListDescription.Count == 0)
                lblPostojeciOpisi.Text = "";
            else
                lblPostojeciOpisi.Text = "Postojeci opisi : ";


        }
        private void BindeAddress(int id)
        {
            Address temp = DAOwners.getAddresbyAddresID(id);

            StreetNumberInput.Text = temp.StreetNumber.ToString();
            ApartmentNumberInput.Text = temp.ApartmentNumber.ToString();
            Address1Input.Text = temp.Address1.ToString();
            Address2Input.Text = temp.Address2.ToString();
            Cities cit = DAOwners.getCityByCityID(Convert.ToInt32(temp.CityID));
            CityInput.Text = cit.Name;


            CountryDropDownList.SelectedIndex = Convert.ToInt32(cit.CountryID);

        }
        private void BindePeriod()
        {
            ListPrices = DAOwners.getAllPricesByApartmanID(ApartmanID);
            PostojeciPeriodiRepeater.DataSource = ListPrices;
            PostojeciPeriodiRepeater.DataBind();
        }
        protected void AddNewPeriod_Click(object sender, EventArgs e)
        {

            //izvrsiti provjeru da li postoji period unutar liste
            if (Convert.ToInt32(CurrencyDropDownList.SelectedIndex) != 0
                && StartPeriodInput.Value != ""
                && EndPeriodInput.Value != ""
                && PriceInput.Text != ""
                )
            {
                bool valid = false;

                Prices p = new Prices();

                p.currency_code = CurrencyDropDownList.SelectedItem.Text;
                p.currency_id = Convert.ToInt32(CurrencyDropDownList.SelectedValue);
                p.PeriodStart = Convert.ToDateTime(StartPeriodInput.Value);
                p.PeriodEnd = Convert.ToDateTime(EndPeriodInput.Value);
                p.Price = Convert.ToDecimal(PriceInput.Text);

                if (pricesList.Count == 0)
                    valid = true;
                for (int i = 0; i < pricesList.Count; i++)
                {
                    if (p.PeriodStart >= pricesList[i].PeriodStart && p.PeriodEnd <= pricesList[i].PeriodEnd)
                    {
                        valid = false;
                        break;
                    }
                    else if (p.PeriodStart >= pricesList[i].PeriodEnd && p.PeriodEnd > p.PeriodStart)
                    {
                        valid = true;
                    }
                }

                if (valid)
                {
                    PriceID++;
                    p.PriceID = PriceID;

                    pricesList.Add(p);

                    CurrencyDropDownList.SelectedIndex = 0;
                    StartPeriodInput.Value = "";
                    EndPeriodInput.Value = "";
                    PriceInput.Text = "";
                    BindePrice();

                    AlertMessage("Uspjesno dodan novi period !");

                }
                else
                    AlertMessage("Problem sa Pocetnim i Krajnjim Periodom");
            }
        }
        private void BindePrice()
        {

            PeriodRepeater.DataSource = pricesList;
            PeriodRepeater.DataBind();

        }
        private void AlertMessage(string errorMsg)
        {

            string message = "alert('" + errorMsg + "')";
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "alert", message, true);


        }
        protected void UploadImagesButton_Click(object sender, EventArgs e)
        {
            int apartmantCount = DAOwners.getApartmansCount(Convert.ToInt32(HttpContext.Current.User.Identity.Name));
            apartmantCount++;
            string putanja = "~/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString()
                            + "/" + Convert.ToInt32(apartmantCount).ToString();

            slikaID = DAOwners.getPicturesCount(ApartmanID);
            slikaID++;

            if (fuProfiePictures.PostedFiles.Count != 0)
            {
                if (!Directory.Exists(putanja))
                {
                    Directory.CreateDirectory(Server.MapPath(putanja));

                    for (int i = 0; i < fuProfiePictures.PostedFiles.Count; i++)
                    {
                        if (fuProfiePictures.PostedFiles[i].ContentType == "image/jpg" || fuProfiePictures.PostedFiles[i].ContentType == "image/JPG")
                        {

                            Pictures temp_Pictures = new Pictures();

                            HttpPostedFile myFile = fuProfiePictures.PostedFiles[i];//Get Slected Image
                            int nFileLen = myFile.ContentLength;//Get slected Image Size
                            //string myimag = slikaID.ToString();//Get user input image name
                            Guid ImageName = Guid.NewGuid();//get unique id
                            // Read file into a data stream
                            byte[] myData = new Byte[nFileLen];
                            myFile.InputStream.Read(myData, 0, nFileLen);
                            myFile.InputStream.Dispose();
                            string pathTemp = putanja + "/" + "Temp";

                            if (!Directory.Exists(pathTemp))
                            {
                                Directory.CreateDirectory(Server.MapPath(pathTemp));
                                // Save the stream to disk as temporary file. make sure the path is unique!
                                System.IO.FileStream newFile
                                        = new System.IO.FileStream(Server.MapPath(pathTemp + "/" + slikaID.ToString() + ".jpg"), System.IO.FileMode.Create);
                                newFile.Write(myData, 0, myData.Length);
                                if (!Directory.Exists(putanja + "/Thumbnail"))
                                {
                                    Directory.CreateDirectory(Server.MapPath(putanja + "/Thumbnail"));
                                    bool success = ResizeImageAndUpload(newFile, putanja + "/Thumbnail" + "/" + slikaID.ToString(), 350, 350, ".jpg");//Save image your thumb image path
                                    if (success)
                                        temp_Pictures.UrlThumbnail = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Thumbnail" + "/" + slikaID.ToString() + ".jpg";
                                    if (!Directory.Exists(putanja + "/Big"))
                                    {
                                        Directory.CreateDirectory(Server.MapPath(putanja + "/Big"));
                                        success = ResizeImageAndUpload(newFile, putanja + "/Big" + "/" + slikaID.ToString(), 1024, 1024, ".jpg");//Save image your normal image path
                                        if (success)
                                            temp_Pictures.Url = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Big" + "/" + slikaID.ToString() + ".jpg";
                                    }
                                    //delete the temp file.
                                    newFile.Close();
                                    //Directory.Delete(pathTemp, true);
                                }
                            }

                            temp_Pictures.PictureID = slikaID;
                            picturesList.Add(temp_Pictures);
                            slikaID++;

                        }
                        else if (fuProfiePictures.PostedFiles[i].ContentType == "image/jpeg" || fuProfiePictures.PostedFiles[i].ContentType == "image/JPEG")
                        {
                            Pictures temp_Pic = new Pictures();

                            HttpPostedFile myFile = fuProfiePictures.PostedFiles[i];//Get Slected Image
                            int nFileLen = myFile.ContentLength;//Get slected Image Size
                            //string myimag = slikaID.ToString();//Get user input image name
                            Guid ImageName = Guid.NewGuid();//get unique id
                            // Read file into a data stream
                            byte[] myData = new Byte[nFileLen];
                            myFile.InputStream.Read(myData, 0, nFileLen);
                            myFile.InputStream.Dispose();
                            string pathTemp = putanja + "/Temp";
                            if (!Directory.Exists(pathTemp))
                            {
                                Directory.CreateDirectory(Server.MapPath(pathTemp));
                                // Save the stream to disk as temporary file. make sure the path is unique!
                                System.IO.FileStream newFile
                                        = new System.IO.FileStream(Server.MapPath(pathTemp + "/" + slikaID.ToString()), System.IO.FileMode.Create);
                                newFile.Write(myData, 0, myData.Length);
                                if (!Directory.Exists(putanja + "/Thumbnail"))
                                {
                                    Directory.CreateDirectory(Server.MapPath(putanja + "/Thumbnail"));
                                    bool success = ResizeImageAndUpload(newFile, putanja + "/Thumbnail" + "/" + slikaID.ToString(), 350, 350, ".jpeg");//Save image your thumb image path
                                    if (success)
                                        temp_Pic.UrlThumbnail = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Thumbnail" + "/" + slikaID.ToString() + ".jpeg";
                                    if (!Directory.Exists(putanja + "/Big"))
                                    {
                                        Directory.CreateDirectory(Server.MapPath(putanja + "/Big"));
                                        success = ResizeImageAndUpload(newFile, putanja + "/Big" + "/" + slikaID.ToString(), 1024, 1024, ".jpeg");//Save image your normal image path
                                        if (success)
                                            temp_Pic.Url = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Big" + "/" + slikaID.ToString() + ".jpeg";
                                    }
                                    //delete the temp file.
                                    newFile.Close();
                                    //Directory.Delete(pathTemp, true);
                                }
                            }

                            picturesList.Add(temp_Pic);
                            slikaID++;
                        }

                        else
                            if (fuProfiePictures.PostedFiles[i].ContentType == "image/png" || fuProfiePictures.PostedFiles[i].ContentType == "image/PNG")
                            {

                                Pictures temp = new Pictures();

                                HttpPostedFile myFile = fuProfiePictures.PostedFiles[i];//Get Slected Image
                                int nFileLen = myFile.ContentLength;//Get slected Image Size
                                //string myimag = slikaID.ToString();//Get user input image name
                                Guid ImageName = Guid.NewGuid();//get unique id
                                // Read file into a data stream
                                byte[] myData = new Byte[nFileLen];
                                myFile.InputStream.Read(myData, 0, nFileLen);
                                myFile.InputStream.Dispose();
                                string pathTemp = putanja + "/Temp";
                                if (!Directory.Exists(pathTemp))
                                {
                                    Directory.CreateDirectory(Server.MapPath(pathTemp));
                                    // Save the stream to disk as temporary file. make sure the path is unique!
                                    System.IO.FileStream newFile
                                            = new System.IO.FileStream(Server.MapPath(pathTemp + "/" + slikaID.ToString() + ".png"), System.IO.FileMode.Create);
                                    newFile.Write(myData, 0, myData.Length);

                                    string pathThumb = putanja + "/Thumbnail";

                                    if (!Directory.Exists(pathThumb))
                                    {
                                        Directory.CreateDirectory(Server.MapPath(pathThumb));
                                        bool success = ResizeImageAndUpload(newFile, putanja + "/Thumbnail" + "/" + slikaID.ToString(), 350, 350, ".png");//Save image your thumb image path
                                        if (success)
                                            temp.UrlThumbnail = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Thumbnail" + "/" + slikaID.ToString() + ".png";
                                        string pathBig = putanja + "/Big";
                                        if (!Directory.Exists(pathBig))
                                        {
                                            Directory.CreateDirectory(Server.MapPath(pathBig));
                                            success = ResizeImageAndUpload(newFile, putanja + "/Big" + "/" + slikaID.ToString(), 1024, 1024, ".png");//Save image your normal image path
                                            if (success)
                                                temp.Url = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Big" + "/" + slikaID.ToString() + ".png";
                                        }
                                        //delete the temp file.
                                        newFile.Close();
                                        //Directory.Delete(pathTemp, true);
                                    }
                                }
                                picturesList.Add(temp);
                                slikaID++;

                            }
                            else
                                if (fuProfiePictures.PostedFiles[i].ContentType == "image/gif" || fuProfiePictures.PostedFiles[i].ContentType == "image/GIF")
                                {
                                    Pictures temp = new Pictures();

                                    HttpPostedFile myFile = fuProfiePictures.PostedFiles[i];//Get Slected Image
                                    int nFileLen = myFile.ContentLength;//Get slected Image Size
                                    //string myimag = slikaID.ToString();//Get user input image name
                                    Guid ImageName = Guid.NewGuid();//get unique id
                                    // Read file into a data stream
                                    byte[] myData = new Byte[nFileLen];
                                    myFile.InputStream.Read(myData, 0, nFileLen);
                                    myFile.InputStream.Dispose();
                                    string pathTemp = putanja + "/Temp";
                                    if (!Directory.Exists(pathTemp))
                                    {
                                        Directory.CreateDirectory(Server.MapPath(pathTemp));
                                        // Save the stream to disk as temporary file. make sure the path is unique!
                                        System.IO.FileStream newFile
                                                = new System.IO.FileStream(Server.MapPath(pathTemp + "/" + slikaID.ToString() + ".gif"), System.IO.FileMode.Create);
                                        newFile.Write(myData, 0, myData.Length);
                                        if (!Directory.Exists(putanja + "/Thumbnail"))
                                        {
                                            Directory.CreateDirectory(Server.MapPath(putanja + "/Thumbnail"));
                                            bool success = ResizeImageAndUpload(newFile, putanja + "/Thumbnail" + "/" + slikaID.ToString(), 350, 350, ".gif");//Save image your thumb image path
                                            if (success)
                                                temp.UrlThumbnail = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Thumbnail" + "/" + slikaID.ToString() + ".gif";
                                            if (!Directory.Exists(putanja + "/Big"))
                                            {
                                                Directory.CreateDirectory(Server.MapPath(putanja + "/Big"));
                                                success = ResizeImageAndUpload(newFile, putanja + "/Big" + "/" + slikaID.ToString(), 1024, 1024, ".gif");//Save image your normal image path
                                                if (success)
                                                    temp.Url = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Big" + "/" + slikaID.ToString() + ".gif";
                                            }
                                            //delete the temp file.
                                            newFile.Close();
                                            //Directory.Delete(pathTemp, true);
                                        }
                                    }
                                    picturesList.Add(temp);
                                    slikaID++;
                                }
                                else
                                    if (fuProfiePictures.PostedFiles[i].ContentType == "image/bmp" || fuProfiePictures.PostedFiles[i].ContentType == "image/BMP")
                                    {
                                        Pictures temp = new Pictures();

                                        HttpPostedFile myFile = fuProfiePictures.PostedFiles[i];//Get Slected Image
                                        int nFileLen = myFile.ContentLength;//Get slected Image Size
                                        //string myimag = slikaID.ToString();//Get user input image name
                                        Guid ImageName = Guid.NewGuid();//get unique id
                                        // Read file into a data stream
                                        byte[] myData = new Byte[nFileLen];
                                        myFile.InputStream.Read(myData, 0, nFileLen);
                                        myFile.InputStream.Dispose();
                                        string pathTemp = putanja + "/Temp";
                                        if (!Directory.Exists(pathTemp))
                                        {
                                            Directory.CreateDirectory(Server.MapPath(pathTemp));
                                            // Save the stream to disk as temporary file. make sure the path is unique!
                                            System.IO.FileStream newFile
                                                    = new System.IO.FileStream(Server.MapPath(pathTemp + "/" + slikaID.ToString() + ".bmp"), System.IO.FileMode.Create);
                                            newFile.Write(myData, 0, myData.Length);
                                            if (!Directory.Exists(putanja + "/Thumbnail"))
                                            {
                                                Directory.CreateDirectory(Server.MapPath(putanja + "/Thumbnail"));
                                                bool success = ResizeImageAndUpload(newFile, putanja + "/Thumbnail" + "/" + slikaID.ToString(), 350, 350, ".bmp");//Save image your thumb image path
                                                if (success)
                                                    temp.UrlThumbnail = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Thumbnail" + "/" + slikaID.ToString() + ".bmp";
                                                if (!Directory.Exists(putanja + "/Big"))
                                                {
                                                    Directory.CreateDirectory(Server.MapPath(putanja + "/Big"));
                                                    success = ResizeImageAndUpload(newFile, putanja + "/Big" + "/" + slikaID.ToString(), 1024, 1024, ".bmp");//Save image your normal image path
                                                    if (success)
                                                        temp.Url = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Big" + "/" + slikaID.ToString() + ".bmp";
                                                }
                                                //delete the temp file.
                                                newFile.Close();
                                                //Directory.Delete(pathTemp, true);
                                            }
                                        }
                                        picturesList.Add(temp);
                                        slikaID++;
                                    }
                    }

                    ImagesRepeater.DataSource = picturesList;
                    ImagesRepeater.DataBind();

                    slikaID++;
                }
            }
            if (ProfilePicturesFileUpload.PostedFile.ContentLength != 0)
            {
                if (ProfilePicturesFileUpload.PostedFile.ContentType == "image/jpg" || ProfilePicturesFileUpload.PostedFile.ContentType == "image/JPG")
                {

                    HttpPostedFile myFile = ProfilePicturesFileUpload.PostedFile;//Get Slected Image
                    int nFileLen = myFile.ContentLength;//Get slected Image Size
                    //string myimag = slikaID.ToString();//Get user input image name
                    Guid ImageName = Guid.NewGuid();//get unique id
                    // Read file into a data stream
                    byte[] myData = new Byte[nFileLen];
                    myFile.InputStream.Read(myData, 0, nFileLen);
                    myFile.InputStream.Dispose();
                    string pathTemp = putanja + "/" + "Temp";
                    if (!Directory.Exists(pathTemp))
                    {
                        Directory.CreateDirectory(Server.MapPath(pathTemp));
                        // Save the stream to disk as temporary file. make sure the path is unique!
                        System.IO.FileStream newFile
                                = new System.IO.FileStream(Server.MapPath(pathTemp + "/" + (1).ToString() + ".jpg"), System.IO.FileMode.Create);
                        newFile.Write(myData, 0, myData.Length);
                        if (!Directory.Exists(putanja + "/Profile"))
                        {
                            Directory.CreateDirectory(Server.MapPath(putanja + "/Profile"));
                            bool success = ResizeImageAndUpload(newFile, putanja + "/Profile" + "/" + (1).ToString(), 137, 270, ".jpg");//Save image your normal image path
                            if (success)
                                ProfilePictures = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Profile" + "/" + (1).ToString() + ".jpg";

                        }

                        //delete the temp file.
                        newFile.Close();
                        //Directory.Delete(pathTemp, true);
                    }
                }
                else if (ProfilePicturesFileUpload.PostedFile.ContentType == "image/jpeg" || ProfilePicturesFileUpload.PostedFile.ContentType == "image/JPEG")
                {
                    HttpPostedFile myFile = ProfilePicturesFileUpload.PostedFile;//Get Slected Image
                    int nFileLen = myFile.ContentLength;//Get slected Image Size
                    //string myimag = slikaID.ToString();//Get user input image name
                    Guid ImageName = Guid.NewGuid();//get unique id
                    // Read file into a data stream
                    byte[] myData = new Byte[nFileLen];
                    myFile.InputStream.Read(myData, 0, nFileLen);
                    myFile.InputStream.Dispose();
                    string pathTemp = putanja + "/" + "Temp";
                    if (!Directory.Exists(pathTemp))
                    {
                        Directory.CreateDirectory(Server.MapPath(pathTemp));
                        // Save the stream to disk as temporary file. make sure the path is unique!
                        System.IO.FileStream newFile
                                = new System.IO.FileStream(Server.MapPath(pathTemp + "/" + (1).ToString() + ".jpeg"), System.IO.FileMode.Create);
                        newFile.Write(myData, 0, myData.Length);
                        if (!Directory.Exists(putanja + "/Profile"))
                        {
                            Directory.CreateDirectory(Server.MapPath(putanja + "/Profile"));
                            bool success = ResizeImageAndUpload(newFile, putanja + "/Profile" + "/" + (1).ToString(), 137, 270, ".jpeg");//Save image your normal image path
                            if (success)
                                ProfilePictures = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Profile" + "/" + (1).ToString() + ".jpeg";

                        }

                        //delete the temp file.
                        newFile.Close();
                        //Directory.Delete(pathTemp, true);
                    }
                }
                else if (ProfilePicturesFileUpload.PostedFile.ContentType == "image/png" || ProfilePicturesFileUpload.PostedFile.ContentType == "image/PNG")
                {

                    HttpPostedFile myFile = ProfilePicturesFileUpload.PostedFile;//Get Slected Image
                    int nFileLen = myFile.ContentLength;//Get slected Image Size
                    //string myimag = slikaID.ToString();//Get user input image name
                    Guid ImageName = Guid.NewGuid();//get unique id
                    // Read file into a data stream
                    byte[] myData = new Byte[nFileLen];
                    myFile.InputStream.Read(myData, 0, nFileLen);
                    myFile.InputStream.Dispose();
                    string pathTemp = putanja + "/" + "Temp";
                    if (!Directory.Exists(pathTemp))
                    {
                        Directory.CreateDirectory(Server.MapPath(pathTemp));
                        // Save the stream to disk as temporary file. make sure the path is unique!
                        System.IO.FileStream newFile
                                = new System.IO.FileStream(Server.MapPath(pathTemp + "/" + (1).ToString() + ".png"), System.IO.FileMode.Create);
                        newFile.Write(myData, 0, myData.Length);
                        if (!Directory.Exists(putanja + "/Profile"))
                        {
                            Directory.CreateDirectory(Server.MapPath(putanja + "/Profile"));
                            bool success = ResizeImageAndUpload(newFile, putanja + "/Profile" + "/" + (1).ToString(), 137, 270, ".png");//Save image your normal image path
                            if (success)
                                ProfilePictures = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Profile" + "/" + (1).ToString() + ".png";
                        }

                        //delete the temp file.
                        newFile.Close();
                        //Directory.Delete(pathTemp, true);
                    }

                }
                else if (ProfilePicturesFileUpload.PostedFile.ContentType == "image/gif" || ProfilePicturesFileUpload.PostedFile.ContentType == "image/GIF")
                {


                    HttpPostedFile myFile = ProfilePicturesFileUpload.PostedFile;//Get Slected Image
                    int nFileLen = myFile.ContentLength;//Get slected Image Size
                    //string myimag = slikaID.ToString();//Get user input image name
                    Guid ImageName = Guid.NewGuid();//get unique id
                    // Read file into a data stream
                    byte[] myData = new Byte[nFileLen];
                    myFile.InputStream.Read(myData, 0, nFileLen);
                    myFile.InputStream.Dispose();
                    string pathTemp = putanja + "/" + "Temp";
                    if (!Directory.Exists(pathTemp))
                    {
                        Directory.CreateDirectory(Server.MapPath(pathTemp));
                        // Save the stream to disk as temporary file. make sure the path is unique!
                        System.IO.FileStream newFile
                                = new System.IO.FileStream(Server.MapPath(pathTemp + "/" + (1).ToString() + ".gif"), System.IO.FileMode.Create);
                        newFile.Write(myData, 0, myData.Length);
                        if (!Directory.Exists(putanja + "/Profile"))
                        {
                            Directory.CreateDirectory(Server.MapPath(putanja + "/Profile"));
                            bool success = ResizeImageAndUpload(newFile, putanja + "/Profile" + "/" + (1).ToString(), 137, 270, ".gif");//Save image your normal image path
                            if (success)
                                ProfilePictures = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Profile" + "/" + (1).ToString() + ".gif";

                        }

                        //delete the temp file.
                        newFile.Close();
                        //Directory.Delete(pathTemp, true);
                    }

                }
                else if (ProfilePicturesFileUpload.PostedFile.ContentType == "image/bmp" || ProfilePicturesFileUpload.PostedFile.ContentType == "image/BMP")
                {

                    HttpPostedFile myFile = ProfilePicturesFileUpload.PostedFile;//Get Slected Image
                    int nFileLen = myFile.ContentLength;//Get slected Image Size
                    //string myimag = slikaID.ToString();//Get user input image name
                    Guid ImageName = Guid.NewGuid();//get unique id
                    // Read file into a data stream
                    byte[] myData = new Byte[nFileLen];
                    myFile.InputStream.Read(myData, 0, nFileLen);
                    myFile.InputStream.Dispose();
                    string pathTemp = putanja + "/" + "Temp";
                    if (!Directory.Exists(pathTemp))
                    {
                        Directory.CreateDirectory(Server.MapPath(pathTemp));
                        // Save the stream to disk as temporary file. make sure the path is unique!
                        System.IO.FileStream newFile
                                = new System.IO.FileStream(Server.MapPath(pathTemp + "/" + (1).ToString() + ".bmp"), System.IO.FileMode.Create);
                        newFile.Write(myData, 0, myData.Length);
                        if (!Directory.Exists(putanja + "/Profile"))
                        {
                            Directory.CreateDirectory(Server.MapPath(putanja + "/Profile"));
                            bool success = ResizeImageAndUpload(newFile, putanja + "/Profile" + "/" + (1).ToString(), 137, 270, ".bmp");//Save image your normal image path
                            if (success)
                                ProfilePictures = "/Content/img/Owners/" + Convert.ToInt32(HttpContext.Current.User.Identity.Name).ToString() + "/" + Convert.ToInt32(apartmantCount).ToString() + "/Profile" + "/" + (1).ToString() + ".bmp";

                        }

                        //delete the temp file.
                        newFile.Close();
                        // Directory.Delete(pathTemp, true);
                    }
                }
                ProfileImage.ImageUrl = ProfilePictures;
                if (ProfilePictures != "")
                {
                    profilePicturesDIV.Visible = false;
                    profilePictDIV.Visible = true;
                }

            }
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {

            //Ispitivanje da li postoji vec opis sa istoimenim jezikom . . 
            if (Convert.ToInt32(DescriptionLanguageDropDownList.SelectedIndex) != 0
                && ShortPropertyDescriptionInput.Text != ""
                && AreaDescriptionInput.Text != ""
                && FullPropertyDescriptionInput.Text != ""
                )
            {
                //bool valid = true;
                //if (descriptionsList.Count == 0)
                //    valid = true;

                //for (int i = 0; i < descriptionsList.Count; i++)
                //{
                //    if (descriptionsList[i].Language == DescriptionLanguageDropDownList.SelectedItem.Text)
                //    {
                //        valid = false;
                //        break;
                //    }
                //}

                //if (valid)
                //{
                    lblPostojeci.Visible = true;
                    Descriptions temp = new Descriptions();
                    DescriptionID++;
                    temp.DescriptionID = DescriptionID;
                    temp.ShortPropertyDescription = ShortPropertyDescriptionInput.Text;
                    temp.AreaDescription = AreaDescriptionInput.Text;
                    temp.FullPropertyDescription = FullPropertyDescriptionInput.Text;
                    temp.Language = DescriptionLanguageDropDownList.SelectedItem.Text;
                    descriptionsList.Add(temp);
                    //praznjenje boxova!
                    ShortPropertyDescriptionInput.Text = "";
                    AreaDescriptionInput.Text = "";
                    FullPropertyDescriptionInput.Text = "";
                    //Skrivanje vidljivosti boxova
                    divID.Visible = false;
                    divID2.Visible = true;

                    AlertMessage("Uspjesno dodan novi opis !");



                //}
                //else
                //    AlertMessage("Vec postoji opis na odabranom jeziku !");
            }
            else
                AlertMessage("Problem sa ulaznim podacima !");

            BindDescriptionTemp();

        }
        private void BindDescriptionTemp()
        {

            DescriptionRepeater.DataSource = descriptionsList;
            DescriptionRepeater.DataBind();
        }
        protected void AddLanguageBtn_Click(object sender, EventArgs e)
        {

            if (Convert.ToInt32(DescriptionLanguageDropDownList.SelectedIndex) != 0)
            {
                bool valid = false;
                if (descriptionsList.Count == 0)
                    valid = true;


                for (int i = 0; i < descriptionsList.Count; i++)
                {
                    if (descriptionsList[i].Language == DescriptionLanguageDropDownList.SelectedItem.Text)
                    {

                        valid = false;
                        break;
                    }
                }
                for (int i = 0; i < ListDescription.Count; i++)
                {
                    if(ListDescription[i].Language == DescriptionLanguageDropDownList.SelectedItem.Text)
                    {
                        valid = false;
                        break;
                    }
                    
                }

                if (valid)
                {
                    divID.Visible = true;
                    lblAreaDescription.InnerText = "";
                    lblAreaDescription.InnerText = "Short property description -  " + DescriptionLanguageDropDownList.SelectedItem.Text;
                    lblShortPropertyDescription.InnerText = "";
                    lblShortPropertyDescription.InnerText = "Area description - " + DescriptionLanguageDropDownList.SelectedItem.Text;
                    lblFullPropertyDescription.InnerText = "";
                    lblFullPropertyDescription.InnerText = "Full property description - " + DescriptionLanguageDropDownList.SelectedItem.Text;
                    ShortPropertyDescriptionInput.Focus();
                }
                else
                {
                    AlertMessage("Opis na odabranom jezik je vec odabran !");

                }
            }
            else
            {
                AlertMessage("Odaberi jezik !");

            }

        }
        protected void DescriptionRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "DeleteDescriptionButton")
            {
                int ID = (Convert.ToInt32(e.CommandArgument));
              
                int lokacija = 0;
                for (int i = 0; i < descriptionsList.Count; i++)
                {
                    if (descriptionsList[i].DescriptionID == ID)
                    {
                        lokacija = i;
                        break;
                    }
                }

                descriptionsList.RemoveAt(lokacija);


                BindDescriptionTemp();


            }
        }
        protected void PeriodRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "DeletePriceButton")
            {
                int ID = (Convert.ToInt32(e.CommandArgument));
                Prices tepPrice = new Prices();

                int lokacija = 0;
                for (int i = 0; i < pricesList.Count; i++)
                {
                    if (pricesList[i].PriceID == ID)
                    {
                        lokacija = i;
                        break;
                    }
                }
                pricesList.RemoveAt(lokacija);

                BindePrice();

            }
        }
        protected void PostojeciPeriodiRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "DeletePeriodButton")
            {
                //brisanje perioda iz baze

                DAOwners.DeletePriceByPriceID(Convert.ToInt32(e.CommandArgument), Convert.ToInt32(ApartmanID));
                BindePeriod();


            }
        }
        protected void PostojeciOpisiRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Delete2DescriptionButton")
            {
                DAOwners.DeleteDescriptionByDescriptionID(Convert.ToInt32(e.CommandArgument), Convert.ToInt32(ApartmanID));
                BindDescriptions();
            }
        }
        protected void Images2Repeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "DeletePicturesButton")
            {
                DAOwners.deletePicture(Convert.ToInt32(e.CommandArgument));
                BindPictures();


            }


        }
        protected void ImagesRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "DeletePictures1Button")
            {
                int ID = Convert.ToInt32(e.CommandArgument);
                int lokacija = 0;
                for (int i = 0; i < picturesList.Count; i++)
                {
                    if(picturesList[i].PictureID == ID)
                    {
                        lokacija = i;
                        break;
                    }
                }
                picturesList.RemoveAt(lokacija);
                ImagesRepeater.DataSource = picturesList;
                ImagesRepeater.DataBind();



            }


        }


        public bool ResizeImageAndUpload(System.IO.FileStream newFile, string folderPathAndFilenameNoExtension, double maxHeight, double maxWidth, string type)
        {
            try
            {
                // Declare variable for the conversion
                float ratio;
                // Create variable to hold the image
                System.Drawing.Image thisImage = System.Drawing.Image.FromStream(newFile);
                // Get height and width of current image
                int width = (int)thisImage.Width;
                int height = (int)thisImage.Height;
                // Ratio and conversion for new size
                if (width > maxWidth)
                {
                    ratio = (float)width / (float)maxWidth;
                    width = (int)(width / ratio);
                    height = (int)(height / ratio);
                }
                // Ratio and conversion for new size
                if (height > maxHeight)
                {
                    ratio = (float)height / (float)maxHeight;
                    height = (int)(height / ratio);
                    width = (int)(width / ratio);
                }
                // Create "blank" image for drawing new image
                Bitmap outImage = new Bitmap(width, height);
                Graphics outGraphics = Graphics.FromImage(outImage);
                SolidBrush sb = new SolidBrush(System.Drawing.Color.White);
                // Fill "blank" with new sized image
                outGraphics.FillRectangle(sb, 0, 0, outImage.Width, outImage.Height);
                outGraphics.DrawImage(thisImage, 0, 0, outImage.Width, outImage.Height);
                sb.Dispose();
                outGraphics.Dispose();
                thisImage.Dispose();
                // Save new image as jpg

                if (type == ".jpeg")
                {
                    outImage.Save(Server.MapPath(folderPathAndFilenameNoExtension + type), System.Drawing.Imaging.ImageFormat.Jpeg);
                    outImage.Dispose();
                    return true;
                }
                else if (type == ".jpg")
                {
                    outImage.Save(Server.MapPath(folderPathAndFilenameNoExtension + type), System.Drawing.Imaging.ImageFormat.Jpeg);
                    outImage.Dispose();
                    return true;
                }
                else if (type == ".png")
                {
                    outImage.Save(Server.MapPath(folderPathAndFilenameNoExtension + type), System.Drawing.Imaging.ImageFormat.Png);
                    outImage.Dispose();
                    return true;
                }
                else if (type == ".gif")
                {
                    outImage.Save(Server.MapPath(folderPathAndFilenameNoExtension + type), System.Drawing.Imaging.ImageFormat.Gif);
                    outImage.Dispose();
                    return true;
                }
                else if (type == ".bmp")
                {
                    outImage.Save(Server.MapPath(folderPathAndFilenameNoExtension + type), System.Drawing.Imaging.ImageFormat.Bmp);
                    outImage.Dispose();
                    return true;
                }
                else
                    return false;

            }
            catch (Exception)
            {
                return false;
            }
        }

        protected void UpdateApartman_Click(object sender, EventArgs e)
        {

            Apartments apartment = new Apartments();
            List<int> amenitiesList = new List<int>();
            List<int> nearByActvitiesList = new List<int>();
            Address address = new Address();

            for (int i = 0; i < AmenitiesCheckBoxList.Items.Count; i++)
            {
                if (AmenitiesCheckBoxList.Items[i].Selected)
                    amenitiesList.Add(Convert.ToInt32(AmenitiesCheckBoxList.Items[i].Value));
            }

            for (int i = 0; i < NearByActivitiesCheckBoxList.Items.Count; i++)
            {
                if (NearByActivitiesCheckBoxList.Items[i].Selected)
                    nearByActvitiesList.Add(Convert.ToInt32(NearByActivitiesCheckBoxList.Items[i].Value));
            }
            apartment.ApartmentID = ApartmanID;
            apartment.Title = TitleInput.Text;
            apartment.ApartmentTypeID = Convert.ToInt32(TypeDropDownList.SelectedIndex);
            apartment.Bedrooms = Convert.ToInt32(BedroomsDropDownList.SelectedIndex);
            apartment.CheckIn = Convert.ToDateTime(CheckInInput.Text);
            apartment.CheckOut = Convert.ToDateTime(CheckOutInput.Text);
            apartment.Beds = Convert.ToInt32(BedsDropDownList.SelectedIndex);
            apartment.AvgCleaningTime = Convert.ToDateTime(AvgCleaningTimeInput.Text);
            apartment.ProfilePictures = ProfilePictures;

            if (Convert.ToInt32(ElevatorDropDownList.SelectedIndex) == 1)
                apartment.Elevator = true;
            else if (Convert.ToInt32(ElevatorDropDownList.SelectedIndex) == 2)
                apartment.Elevator = false;

            apartment.Floor = Convert.ToInt32(FloorInputDropDownList.SelectedIndex);
            apartment.Bathrooms = Convert.ToInt32(BathroomsDropDownList.SelectedIndex);
            apartment.Toilets = Convert.ToInt32(ToiletsDropDownList.SelectedIndex);
            apartment.MaxGuests = Convert.ToInt32(MaxGuestDropDownList.SelectedIndex);
            apartment.MaxAdults = Convert.ToInt32(MaxAdultsDropDownList1.SelectedIndex);
            apartment.MaxChildren = Convert.ToInt32(MaxChlidrenDropDownList.SelectedIndex);
            apartment.MaxBabies = Convert.ToInt32(MaxBabiesDropDownList.SelectedIndex);
            apartment.MinStay = Convert.ToInt32(MinStayDropDownList.SelectedIndex);
            apartment.MaxStay = Convert.ToInt32(MaxStayDropDownList.SelectedIndex);
            apartment.RentalDetails = RentalDetailsInput.Text;
            apartment.Inventory = InventoryInput.Text;
            apartment.ArrivalSheet = ArrivalSheetInput.Text;

            address.StreetNumber = Convert.ToInt32(StreetNumberInput.Text);
            address.ApartmentNumber = Convert.ToInt32(ApartmentNumberInput.Text);
            address.Address1 = Address1Input.Text;
            address.Address2 = Address2Input.Text;

            Cities cit = new Cities();
            cit.Name = CityInput.Text;
            cit.CountryID = Convert.ToInt32(CountryDropDownList.SelectedIndex);

            DAOwners.UpdateApartman(Convert.ToInt32(HttpContext.Current.User.Identity.Name), apartment, pricesList, picturesList, descriptionsList, amenitiesList, nearByActvitiesList, address, cit);

            //poruka o uspjesno dodanom apartmanu
            AlertMessage("Uspjesno spremljene promjene !");

        }
    }
}